package gdma.hqdes.stat.bean;

import com.deepoove.poi.data.SeriesRenderData;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import gdma.hqdes.bean.HqdIndex;
import gdma.hqdes.bean.IndexInfo;
import gdma.hqdes.bean.StatIndex;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @Author wangyue
 * @Version 3.0
 * @Date 2024-07-31
 */
@Data
public class IndexCombo {

    public static final int TYPE_HQD_INDEX = 1;
    public static final int TYPE_STAT_INDEX = 2;

    @ApiModelProperty("指标对象类：1=HqdIndex类，2=StatIndex类")
    int type;

    @ApiModelProperty("指标对象：参见 HqdIndex 和 StatIndex 对象")
    @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type")
    @JsonSubTypes({
        @JsonSubTypes.Type(value = HqdIndex.class, name = "1"),
        @JsonSubTypes.Type(value = StatIndex.class, name = "2")
    })
    IndexInfo indexObject;

    @ApiModelProperty("图表样式，取值：BAR, LINE, AREA")
    SeriesRenderData.ComboType comboType;

    @ApiModelProperty("降排序优先级：数字越小优先级越高")
    Integer descOrder;

    public String toIdString() {
        StringBuilder s = new StringBuilder();
        if(indexObject instanceof HqdIndex)
            s.append(indexObject.getId());
        else if(indexObject instanceof StatIndex)
            s.append("s").append(indexObject.getId());
        if(comboType != null) s.append(comboType.toString().toLowerCase().charAt(0));
        if(descOrder != null) s.append(descOrder);
        return s.toString();
    }

    public String toCodeString() {
        StringBuilder s = new StringBuilder();
        if(indexObject instanceof HqdIndex)
            s.append(indexObject.getCode());
        else if(indexObject instanceof StatIndex)
            s.append(indexObject.getCode());
        if(comboType != null) s.append(comboType.toString().toLowerCase().charAt(0));
        if(descOrder != null) s.append(descOrder);
        return s.toString();
    }

}
